'''
coding:utf-8
:writingtime: 2022-6-26
:author: wanjun
:reference: Associated probabilities’ aggregations in interactive multiattribute
            decision making for q‐rung orthopair fuzzy discrimination environment
:doi: 10.1002/int.22206
:examiner:
'''

import os
from Utilities.AutoGetOperator.selectPackage import get_func


Operator_IVQ_ROFS=get_func(r'Operators/OperationOperators/OperatorIVQROF.py','Operator_IVQ_ROFS')


class AssociatedProbabilitiesA(Operator_IVQ_ROFS):
    def __init__(self, data_list=[], weight_list=[], q=3, x=0.2, a=2, b=2, prob_list=[]):
        '''
        function: AssociatedProbabilitiesOperator
        :param data_list:
        :param weight_list:
        :param prob_list: 对象的概率值
        :param q:
        :param x:
        :param a:
        :param b:
        '''

        if len(prob_list):
            self.prob_list = prob_list
        else:
            self.prob_list=[1/len(data_list) for _ in range(len(data_list))]

        super(AssociatedProbabilitiesA,self).__init__(data_list, weight_list, q, x, a, b)

    def getResult(self):
        '''

        :return:
        '''

        result=self.kmulti(self.data_list[0],self.prob_list[0])

        for i in range(len(self.data_list)):
            temp=self.kmulti(self.data_list[i],self.prob_list[i])
            result=self.add(result,temp)

        return result

class AssociatedProbabilitiesGA(Operator_IVQ_ROFS):
    def __init__(self, data_list=[], weight_list=[], q=3, x=0.2, a=2, b=2, prob_list=[]):
        '''
        function: AssociatedProbabilitiesOperator
        :param data_list:
        :param weight_list:
        :param prob_list: 对象的概率值
        :param q:
        :param x:
        :param a:
        :param b:
        '''

        if len(prob_list):
            self.prob_list = prob_list
        else:
            self.prob_list=[1/len(data_list) for _ in range(len(data_list))]

        super(AssociatedProbabilitiesGA,self).__init__(data_list, weight_list, q, x, a, b)

    def getResult(self):
        '''

        :return:
        '''

        result=self.pow(self.data_list[0],self.prob_list[0])

        for i in range(len(self.data_list)):
            temp=self.pow(self.data_list[i],self.prob_list[i])
            result=self.multi(result,temp)

        return result

class AssociatedProbabilitiesWA(Operator_IVQ_ROFS):
    def __init__(self, data_list=[], weight_list=[], q=3, x=0.4, a=2, b=2, prob_list=[]):
        '''
        function: AssociatedProbabilitiesOperator
        :param data_list:
        :param weight_list:
        :param prob_list: 对象的概率值
        :param q:
        :param x:
        :param a:
        :param b:
        '''

        if len(prob_list):
            self.prob_list = [prob_list[i]*x+(1-x)*weight_list[i] for i in range(len(data_list))]
        else:
            self.prob_list=[1/len(data_list) for _ in range(len(data_list))]
            self.prob_list = [self.prob_list[i]*x+(1-x)*weight_list[i] for i in range(len(data_list))]

        super(AssociatedProbabilitiesWA,self).__init__(data_list, weight_list, q, x, a, b)


    def getResult(self):
        '''

        :return:
        '''

        result=self.kmulti(self.data_list[0],self.prob_list[0])

        for i in range(len(self.data_list)):
            temp=self.kmulti(self.data_list[i],self.prob_list[i])
            result=self.add(result,temp)
        return result

class AssociatedProbabilitiesWGA(Operator_IVQ_ROFS):
    def __init__(self, data_list=[], weight_list=[], q=3, x=0.2, a=2, b=2, prob_list=[]):
        '''
        function: AssociatedProbabilitiesOperator
        :param data_list:
        :param weight_list:
        :param prob_list: 对象的概率值
        :param q:
        :param x:
        :param a:
        :param b:
        '''

        if len(prob_list):
            self.prob_list = prob_list
        else:
            self.prob_list=[1/len(data_list) for _ in range(len(data_list))]

        super(AssociatedProbabilitiesWGA,self).__init__(data_list, weight_list, q, x, a, b)

    def getResult(self):
        '''

        :return:
        '''

        result=self.pow(self.data_list[0],self.prob_list[0])

        for i in range(len(self.data_list)):
            temp=self.pow(self.data_list[i],self.prob_list[i])
            result=self.multi(result,temp)

        return result

class AssociatedProbabilitiesOWA(Operator_IVQ_ROFS):
    def __init__(self, data_list=[], weight_list=[], q=3, x=0.4, a=2, b=2, prob_list=[]):
        '''
        function: AssociatedProbabilitiesOperator
        :param data_list:
        :param weight_list:
        :param prob_list: 对象的概率值
        :param q:
        :param x:
        :param a:
        :param b:
        '''

        if len(prob_list):
            self.prob_list = [prob_list[i]*x+(1-x)*weight_list[i] for i in range(len(data_list))]
        else:
            self.prob_list=[1/len(data_list) for _ in range(len(data_list))]
            self.prob_list = [self.prob_list[i]*x+(1-x)*weight_list[i] for i in range(len(data_list))]

        super(AssociatedProbabilitiesOWA,self).__init__(data_list, weight_list, q, x, a, b)


    def getResult(self):
        '''

        :return:
        '''
        # 将 数据集备份，将类中数据集属性 替换为 排序后的数据集
        data_list = self.data_list
        self.data_list = self.sortdata()

        result=self.kmulti(self.data_list[0],self.prob_list[0])
        for i in range(len(self.data_list)):
            temp=self.kmulti(self.data_list[i],self.prob_list[i])
            result=self.add(result,temp)

        # 还原数据集
        self.data_list = data_list
        return result

if __name__ == '__main__':
    data_list=[([0.85, 0.95], [0.1, 0.2]), ([0.8, 0.9], [0.1, 0.2]), ([0.85, 0.95], [0.1, 0.2]),
               ([0.7, 0.8], [0.2, 0.3]), ([0.4, 0.5], [0.5, 0.6])]
    weight_list=[0.1, 0.2, 0.3, 0.1, 0.3]
    # Pa = A (data_list)
    # Pa = GA(data_list)
    # Pa = WA(data_list,weight_list)
    # Pa = WGA(data_list,weight_list)
    Pa = AssociatedProbabilitiesOWA(data_list,weight_list)
    print(Pa.getResult())

